
#include "HuffmanTree.h"

HuffmanTree::HuffmanTree() {
	root = new Node();
	chars = new map<char, unsigned int>();
}

void HuffmanTree::addChar(char c) {
	pair< map<char, unsigned int>::iterator, bool> it = chars->insert(pair< char, unsigned int> (c, 1));
	if (!it.second) { // cuando no pudo insertar porque ya estaba
		it.first->second++;
	}
}

map<char, unsigned int> * HuffmanTree::getChars() {
	return chars;
}

void HuffmanTree::setChars(string newChars) {
	chars->clear();
	for (unsigned int i=0; i<newChars.size(); i++) {
		addChar(newChars.at(i));
	}
}

Node* HuffmanTree::getRoot() {
	return root;
}

void HuffmanTree::setRoot(Node* newRoot) {
	root = newRoot;
}

HuffmanTree::~HuffmanTree() {
	delete root;
	chars->clear();
	delete chars;
}

